<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<form id="form-plan-add" class="p-3">
  <div class="form-group">
    <label for="id-add-plan_id">计划编号</label>
    <input type="text" name="plan_id" class="form-control" id="id-add-plan_id">    
  </div>
  <div class="form-group">
    <label for="id-add-standard_id">产品规格编号</label>
    <input type="text" name="standard_id" class="form-control" id="id-add-standard_id">    
  </div>
  <div class="form-group">
    <label for="id-add-cus_id">客户编号</label>
    <input type="text" name="cus_id" class="form-control" id="id-add-cus_id">    
  </div>
  <div class="form-group">
    <label for="id-add-co_id">花色号编号</label>
    <input type="text" name="co_id" class="form-control" id="id-add-co_id">    
  </div>
  <div class="form-group">
    <label for="id-add-plan_xh">生产顺序号</label>
    <input type="text" name="plan_xh" class="form-control" id="id-add-plan_xh">    
  </div>
  <div class="form-group">
    <label for="id-add-plan_month">计划生产月份</label>
    <select id="getYear" name="getYear">
    	<option value="">请选择年份</option>
    </select>
    <select id="getMonth" name="getMonth">
    	<option value="">请选择月份</option>
    </select><br>
    <input type="hidden" id="plan_month" name="plan_month" class="form-control" id="id-add-plan_month">  
  </div>
  <div class="form-group">
    <label for="id-add-plan_num">计划产量</label>
    <input type="text" name="plan_num" class="form-control" id="id-add-plan_num">    
  </div>
  <div class="form-group">
    <label for="id-add-plan_type">产品类型</label>
    <select id="select-plan_type" class="plan-select" name="plan_type">
    			<option value=''>请选择产品类型</option>
    			<option value='1'>白布产品</option>
    			<option value="2">染色产品</option>
    			<option value="3">无底色印花产品</option>
    			<option value="4">有底色印花产品</option>
  	</select>
  </div> 
  
  <button type="button" id="bn-plan-doadd" class="btn btn-primary">保存</button>
</form>

<script>
	//获取当前年月
	var date=new Date();
	var year=date.getFullYear();
	
	var month=date.getMonth();
	
	for(var i=0;i<3;i++){
		$('#getYear').append("<option value='"+(year+i)+"'>"+(year+i)+"</option>");
	}
	//var getYearId=document.getElementById("getYear").value;
	
	/*
	if(false){
		for(var j=0;j<(12-month);j++){
			$('#getMonth').append("<option value='"+(month+j+1)+"'>"+(month+j+1)+"</option>");
		}
	}else{
		for(var j=0;j<12;j++){
			$('#getMonth').append("<option value='"+(j+1)+"'>"+(j+1)+"</option>");
		}
	}
	*/
	$('#getYear').change(function(){
		var getYearId=document.getElementById("getYear").value;
		
		if(getYearId!=""){
			
			$('#getMonth').empty();
			//var getYe=parseInt(getYearId);
			$('#getMonth').append("<option>请选择月份</option>");
			if(getYearId>year){
				for(var j=0;j<12;j++){
					$('#getMonth').append("<option value='"+(j+1)+"'>"+(j+1)+"</option>");
				}
			}else{
				for(var j=0;j<(12-month);j++){
					$('#getMonth').append("<option value='"+(month+j+1)+"'>"+(month+j+1)+"</option>");
				}
			}
			/*
			switch(getYearId){
				case getYearId:
					alert(getYearId);
					for(var j=0;j<(12-month);j++){
						$('#getMonth').append("<option value='"+(month+j+1)+"'>"+(month+j+1)+"</option>");
					}
					break;
				case (getYearId+1):
					alert(getYearId+1);
					for(var j=0;j<12;j++){
						$('#getMonth').append("<option value='"+(j+1)+"'>"+(j+1)+"</option>");
					}
					break;
			}
			*/
		}
	});
		
	//提交表单数据
	$('#bn-plan-doadd').click(function(){
		//获得年和月的值
		var getYear=document.getElementById("getYear").value;
		var getMonth=document.getElementById("getMonth").value;
		
		layer.confirm('你确实要保存该计划信息吗？', {icon: 3, title:'警告'}, function(index){
		//为plan_month添加年和月的值
		document.getElementById("plan_month").value=(getYear+"-"+getMonth);
		
		let loadLayerIdx = layer.load();
		let arr=$('#form-plan-add').serializeArray();
		let data={};
		for(let ele of arr){
			data[ele.name]=ele.value;
		}
		let jsonStr=JSON.stringify(data);
		
		$.ajax({
			url:'manager',
			data:jsonStr,
			method:'post',
			contentType:'application/json',
			dataType:'json'
		})
		.done(function(result){
			layer.close(loadLayerIdx);
			if(result.success){
				reloadData();
				
				layer.msg(result.message, {
						  icon: 1,
						  time: 1000 //1秒关闭（如果不配置，默认是3秒）
						}
				);
				layer.close(layerIdx);
				
			}else{
				layer.msg(result.message, {icon: 6});
			}
		})
		.fail(function(xhr){
			layer.close(loadLayerIdx);
			layer.msg('服务器错误！', {icon: 6});
		});
		layer.close(index);
			
		});
	});
</script>